<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums) {
      let res1 = 0, res2 = 0;
      for (let i = 0; i < nums.length; i++) {
        if (i % 2 === 0 && nums[i] % 2 !== 0) {
          res1++;
        } else if (i % 2 !== 0 && nums[i] % 2 === 0) {
          res1++;
        }
        if (i % 2 === 0 && nums[i] % 2 === 0) {
          res2++;
        } else if (i % 2 !== 0 && nums[i] % 2 !== 0) {
          res2++;
        }
      }
      return Math.min(res1, res2);
    }
    console.log(arr([1, 2, 2, 2, 2]));
  </script>
</body>

</html>